// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-03-15 23:27
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.ArraysTrain;

import org.junit.jupiter.api.Test;

import java.math.BigInteger;

public class PlusOne {
    /**
     * 数组末尾数字+1,数组中只存在单个数字
     *
     * @param digits
     * @return
     */
    public int[] plusOne(int[] digits) {
        int n = digits.length;
        if (++digits[n - 1] <= 9) {
            return digits;
        } else {
            int out = 0;
            for (int i = n - 1; i > 0; i--) {
                if ((digits[i]) > 9) {
                    digits[i] = 0;
                    digits[i - 1]++;
                }
            }
            if (digits[0] > 9) {
                int[] res = new int[n + 1];
                res[0] = digits[0] / 10;
                res[1] = digits[0] % 10;
                for (int i = 2; i < n + 1; i++) {
                    res[i] = digits[i];
                }
                return res;
            }
            return digits;
        }
    }

    @Test
    public void shout() {
        int[] test = {5, 6, 2, 0, 0, 4, 6, 2, 4, 9};
        System.out.println(plusOne(test));
    }
}
